package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import po.Func;
import po.FuncCustom;
import po.Result;
import service.FuncService;

import java.util.List;

@Controller
@RequestMapping("/func")
public class FuncController {
    @Autowired
    private FuncService funcService;

    //返回功能信息界面视图
    @RequestMapping("/getFuncInfoView")
    public String getFuncManageView() {
        return "application/funcInfo";
    }

    //查询功能信息
    @RequestMapping("/findAllFuncCustom")
    public @ResponseBody
    List<FuncCustom> findAllFuncCustom(FuncCustom funcCustom, int page, int rows) throws Exception {
        /*funcCustom.setStart((page-1) * rows);
        funcCustom.setSize(rows);*/
        return funcService.findAllFuncCustom(funcCustom);
    }

    //返回添加功能界面视图
    @RequestMapping("/getAddFuncView")
    public String getAddFuncView() {
        return "application/addFunc";
    }

    //添加功能
    @RequestMapping("/addFunc")
    public @ResponseBody
    Result addFunc(Func func) {
        return funcService.addFunc(func);
    }

    //删除功能
    @RequestMapping("/deleteFuncById")
    public @ResponseBody
    Result deleteFuncById(int id) {
        return funcService.deleteFuncById(id);
    }

    //返回修改功能界面视图
    @RequestMapping("/getEditFuncView")
    public String getEditFuncView() {
        return "application/editFunc";
    }

    //修改功能
    @RequestMapping("/updateFunc")
    public @ResponseBody
    Result updateFunc(Func func) {
        return funcService.updateFuncById(func.getId(), func);
    }
}
